$(document).ready(function() {
	$("#loginForm").validate({
		onkeyup: false,
		onfocusout: false,
		rules: {
			stuNum: {
				required: true,
				digits: true,
				maxlength: 9
			},
			pass: {
				required: true,
				smallEngAndDigits: true,
				rangelength: [6, 20]
			}
		},
		messages: {
			stuNum: {
				required: "<br />*請輸入學號",
				digits: "<br />*學號只能是數字",
				maxlength: "<br />*學號最多9位"
			},
			pass: {
				required: "<br />*請輸入密碼",
				smallEngAndDigits: "<br />*密碼只能是小寫英文或數字",
				rangelength: "<br />*密碼必須在6~20位之間"
			}
		},
		errorPlacement: function(error, element) {
			error.css("color", "red");
			error.css("font-weight", "bold");
			error.insertAfter(element);
		},
		submitHandler: function(form) {
			$("#submitLogin").attr("disabled", "true");
			$(form).ajaxSubmit({
				success: function(resp) {
					if (resp == "0") {
						alert("學號或密碼錯誤");
						$("#submitLogin").removeAttr("disabled");
					}
					else if (resp == "2")
						$(location).attr("href", "./index");
					else
						$(location).attr("href", "./haveNotConfirm?stuNum=" + $("#textStuNum").val() + "&stuName=" + resp);
				}
			});
		}
	})
});